//
//  LYFirstTestCell.m
//  SelectCity
//
//  Created by liuyan on 2019/3/19.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYFirstTestCell.h"

@interface LYFirstTestCell()

//头像
@property (nonatomic, strong) UIImageView *iconImage;
//未读消息
@property (nonatomic, strong) UIView *dotView;
//标题
@property (nonatomic, strong) UILabel *titleLabel;
//时间
@property (nonatomic, strong) UILabel *timeLabel;
//详细
@property (nonatomic, strong) UILabel *detailLabel;

@end


@implementation LYFirstTestCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

#pragma mark - InitSubViews
- (void)initUI {
    UIView *backview = [[UIView alloc] initWithFrame:self.bounds];
    backview.backgroundColor = COLOR_OF_WHITE;
    [self.contentView addSubview:backview];
    
    self.iconImage = [UIToolsControl initImageViewWithFrame:CGRectMake(15, 15, 50, 50) imageName:@"header_bg"];
    self.iconImage.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImage.layer.cornerRadius = self.iconImage.height/2;
    self.imageView.layer.masksToBounds = YES;
    [backview addSubview:self.iconImage];
    
    self.dotView = [[UIView alloc] initWithFrame:CGRectMake(42, 5, 8, 8)];
    self.dotView.layer.cornerRadius = self.dotView.height/2;
    self.dotView.layer.masksToBounds = YES;
    self.dotView.backgroundColor = THEMECOLOR_OF_RED;
    [self.iconImage addSubview:self.dotView];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH - 62, 20, 55, 20)];
    self.timeLabel.textColor = THEMECOLOR_OF_TEXT_9a9a9a;
    self.timeLabel.font = Font(Font_12);
    [backview addSubview:self.timeLabel];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImage.right +8, 20, self.timeLabel.left - self.iconImage.right - 12, 20)];
    self.titleLabel.textColor = THEMECOLOR_OF_TEXT_333333;
    self.titleLabel.font = Font(Font_15);
    [backview addSubview:self.titleLabel];
    
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImage.right +8, self.titleLabel.bottom+3, self.timeLabel.left - self.iconImage.right - 12, 20)];
    self.detailLabel.textColor = THEMECOLOR_OF_TEXT_666666;
    self.detailLabel.font = Font(Font_13);
    [backview addSubview:self.detailLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 79, WIDTH, lineH)];
    line.backgroundColor = THEMECOLOR_OF_TEXT_cccccc;
    [backview addSubview:line];
}
- (void)setHiddenDot:(BOOL)hiddenDot {
    self.dotView.hidden = hiddenDot;
}
- (void)setModel:(LYFirstTestModel *)model {
    NSString *time = model.time;
    self.timeLabel.text = time;
    if ([model.type integerValue] == 1) {
        self.detailLabel.text = [NSString stringWithFormat:@"你有%@条系统消息未查看", model.count];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ", model.name]];
        NSAttributedString *strq = [[NSAttributedString alloc] initWithString:model.company_name attributes:@{NSForegroundColorAttributeName:THEMECOLOR_OF_ORANGE, NSFontAttributeName:Font(Font_13)}];
        [str appendAttributedString:strq];
        self.titleLabel.attributedText = str;
    } else if ([model.type integerValue] == 2) {
        self.detailLabel.text = [NSString stringWithFormat:@"最新%@位企业HR查看",model.count];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:model.name];
        NSAttributedString *strq = [[NSAttributedString alloc] initWithString:@" 查看了您" attributes:@{NSForegroundColorAttributeName:THEMECOLOR_OF_ORANGE, NSFontAttributeName:Font(Font_13)}];
        [str appendAttributedString:strq];
        self.titleLabel.attributedText = str;
    } else {
        self.detailLabel.text = model.currentMessage;
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:model.name];
        NSAttributedString *strq1 = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.company_name] attributes:@{NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666, NSFontAttributeName:Font(Font_13)}];
        [str appendAttributedString:strq1];
        
        NSAttributedString *strq2 = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.job_name] attributes:@{NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666, NSFontAttributeName : Font(Font_13)}];
        [str appendAttributedString:strq2];
        self.titleLabel.attributedText = str;
    }
}

@end
